import type { ID, Timestamp } from './global';

// 内容类型
export type ContentType = 'web' | 'image' | 'video' | 'news' | 'document' | 'academic';

// 搜索排序类型
export type SearchSort = 'relevance' | 'date' | 'popularity' | 'rating';

// 搜索查询接口
export interface SearchQuery {
  text: string;
  filters?: SearchFilters;
  sort?: SearchSort;
  pagination?: PaginationParams;
}

// 搜索筛选器
export interface SearchFilters {
  contentType?: ContentType[];
  dateRange?: {
    start: Date;
    end: Date;
  };
  language?: string[];
  source?: string[];
  fileType?: string[];
  size?: {
    min?: number;
    max?: number;
  };
  rating?: {
    min: number;
    max: number;
  };
  location?: {
    country?: string;
    region?: string;
    city?: string;
  };
}

// 分页参数
export interface PaginationParams {
  page: number;
  pageSize: number;
  offset?: number;
}

// 搜索结果
export interface SearchResult {
  id: ID;
  title: string;
  description: string;
  url: string;
  thumbnail?: string;
  publishDate: Date;
  lastModified?: Date;
  source: string;
  author?: string;
  contentType: ContentType;
  relevanceScore: number;
  popularity?: number;
  rating?: number;
  fileSize?: number;
  language?: string;
  tags?: string[];
  metadata?: Record<string, any>;
  highlights?: {
    title?: string[];
    description?: string[];
    content?: string[];
  };
}

// 搜索建议
export interface SearchSuggestion {
  id: ID;
  text: string;
  type: 'history' | 'suggestion' | 'trending' | 'completion';
  frequency?: number;
  category?: string;
  metadata?: {
    popularity?: number;
    resultCount?: number;
    lastUsed?: Date;
    category?: string;
  };
}

// 搜索历史
export interface SearchHistory {
  id: ID;
  query: string;
  timestamp: Timestamp;
  resultCount: number;
  clickedResults?: ID[];
  filters?: SearchFilters;
}

// 热门搜索
export interface TrendingSearch {
  id: ID;
  query: string;
  rank: number;
  growth: number; // 增长率
  category?: string;
  region?: string;
  timestamp: Timestamp;
}

// 搜索统计
export interface SearchStats {
  totalResults: number;
  searchTime: number; // 毫秒
  suggestions: number;
  filters: SearchFilters;
  timestamp: Timestamp;
}

// 语音搜索配置
export interface VoiceSearchConfig {
  language: string;
  continuous: boolean;
  interimResults: boolean;
  maxAlternatives: number;
  timeout: number;
}

// 图片搜索参数
export interface ImageSearchParams {
  file?: File;
  url?: string;
  base64?: string;
  similarity?: number;
  colorFilter?: string;
  sizeFilter?: 'small' | 'medium' | 'large' | 'xlarge';
  typeFilter?: 'photo' | 'clipart' | 'lineart' | 'face';
}

// 搜索上下文
export interface SearchContext {
  userId?: string;
  sessionId: string;
  userAgent: string;
  location?: {
    country: string;
    region: string;
    city: string;
  };
  preferences?: {
    language: string;
    safeSearch: boolean;
    resultsPerPage: number;
  };
  history?: SearchHistory[];
}

// 搜索响应
export interface SearchResponse {
  results: SearchResult[];
  suggestions?: SearchSuggestion[];
  stats: SearchStats;
  relatedQueries?: string[];
  corrections?: {
    original: string;
    corrected: string;
    confidence: number;
  };
  pagination: {
    page: number;
    pageSize: number;
    total: number;
    totalPages: number;
    hasNext: boolean;
    hasPrev: boolean;
  };
}
